package com.maoshi.shop.platform.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.binarywang.wxpay.service.WxPayService;
import com.maoshi.shop.bean.dto.OrderRefundDto;
import com.maoshi.shop.bean.model.OrderRefund;
import com.maoshi.shop.common.util.PageParam;
import com.maoshi.shop.service.OrderRefundService;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@AllArgsConstructor
@RequestMapping("/platform/orderRefund")
public class OrderRefundController {

    private final OrderRefundService orderRefundService;

    /**
     * 分页查询
     *
     * @param page           分页对象
     * @param orderRefundDto 实体对象
     * @return 分页数据
     */
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('platform:orderRefund:page')")
    public ResponseEntity<IPage<OrderRefundDto>> getOrderRefundPage(PageParam<OrderRefundDto> page, OrderRefundDto orderRefundDto,
                                                                    @RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime) {
        IPage<OrderRefundDto> page1 = orderRefundService.getPage(page, orderRefundDto, startTime, endTime);
        return ResponseEntity.ok(orderRefundService.getPage(page, orderRefundDto, startTime, endTime));
    }

    /**
     * 通过id查询
     *
     * @param refundId id
     * @return 查询详细信息
     */
    @GetMapping("/info")
    @PreAuthorize("@pms.hasPermission('platform:orderRefund:info')")
    public ResponseEntity<OrderRefund> info(@RequestParam("refundId") Long refundId, @RequestParam("shopId") Long shopId) {
        OrderRefund orderRefund = orderRefundService.getOrderRefundById(refundId, shopId);
        return ResponseEntity.ok(orderRefund);
    }

}
